package com.bm.dao;

import com.bm.pojo.user.User;
import org.neo4j.driver.Record;
import org.neo4j.driver.Value;
import org.neo4j.driver.types.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sx
 * Date: 2022/2/10
 * Time: 14:05
 * Description: java
 */
@Repository
public class Neo4jUserDao {
    @Autowired
    private Neo4jIndexDao neo4jUtil;


    public User queryByAccountAndPassword(String account, String password){
        String cql="MATCH (p:User {account:\""+account+"\",password:\""+password+"\"}) RETURN p";
        List<Record>  list = neo4jUtil.setSession(cql);
        Node node = list.get(0).get(0).asNode();
        node.labels();

        Value properties = node.get("properties");
        List<Object> objects = properties.asList();
        Object o = objects.get(0);
        User record = (User)list.get(0);
        return record;
    }

    /**
     *
     * @param account
     * @return
     */

    public User queryByAccount(String account) {
        String cql="match (p:User {account:\""+account+"\"}) return p";
        List list = neo4jUtil.setSession(cql);
        User record = (User)list.get(0);
        return record;
    }


}
